# reshape和flatten
import numpy as np

# reshape
a = np.arange(8).reshape(2, 4)
print(a)
print(a.shape) # (2, 4)

# flatten
b = a.flatten()
print(b)
print(b.shape)

# 三维数组
# （2，3，4）
c = np.arange(24).reshape(2, 3, 4)
print(c) 

# 我要获取[[1,2],[5,6],[9,10]]这个数组如何在c的基础上切片
d = c[0:1, 0:3, 1:3]
print(d)
print("-------------")
# 数组的垂直拼接
a = np.arange(6).reshape(2, 3) 
b = np.arange(6, 12).reshape(2, 3) 
# 垂直拼接

# [[0 1 2 6 7 8] 
#  [3 4 5]] [9 10 11]
#
# ]
e = np.vstack((a, b))
print(e.shape) #    (4, 3)
print(e)

# 数组水平拼接
f = np.hstack((a, b))
print(f.shape) # (2, 6)
print(f)

# 数组的拼接 通用方法 axis=0 行 axis=1 列
g = np.concatenate((a, b), axis=1)
print(g.shape) # (4, 3)
print(g)
print("-------------------------------")
# 数组的拆分
h = np.arange(24).reshape(4, 6)
print(h)
# 垂直拆分
i = np.vsplit(h, 2)
print(i)
print(type(i))
print(type(i[0]))
print(i[0].shape) 

# 水平拆分
j = np.hsplit(h, 3)
print(j)
print(j[0].shape)

# 数组的拆分通用方法 axis=0 行 axis=1 列
k = np.split(h, 2, axis=1)
print(k)
#  拆分第一列和最后一列
l = np.split(h, [1,5], axis=1)
print(l)
